import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Set;
import java.util.StringTokenizer;


public class Agency {
	
	public static void main(String[] args) throws Throwable{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		while(true){
			StringTokenizer st=new StringTokenizer(br.readLine());
			int digitos=Integer.parseInt(st.nextToken());
			String a=st.nextToken();
			String b=st.nextToken();
			st=new StringTokenizer(br.readLine());
			int []costos=new int[digitos];
			int i=0;
			int total=0;
			while(st.hasMoreTokens()){
				costos[i++]=Integer.parseInt(st.nextToken());
				total+=costos[i-1];
			}
			int[] apagar=new int[digitos];
			int[] prender=new int[digitos];

			for ( i = 0; i < digitos; i++) {
				if(a.charAt(i)=='0'&&b.charAt(i)=='1'){
					prender[i]=costos[i];
				}else if(a.charAt(i)=='1'&&b.charAt(i)=='0'){
					apagar[i]=costos[i];
				}
			}
			
			Arrays.sort(prender);
			Arrays.sort(apagar);
			
			
			
		}
	}

}
